package com.inboyu.application.response;

import com.inboyu.operation.domain.Customer;
import lombok.Data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 租赁人实体
 */
@Data
public class CustomerResponse {

    /**
     * 运营商id
     */
    private Long tenantId;

    /**
     * 用户id
     */
    private String userId;

    /**
     * 租赁人id
     */
    private String customerId;

    /**
     * 租赁人姓名
     */
    private String name;

    /**
     * 租赁人手机号
     */
    private String mobile;

    /**
     * 证件类型
     */
    private String certificateType;

    /**
     * 证件号码
     */
    private String certificateNumber;

    public static CustomerResponse toCustomerResponse(Customer customer) {
        if (customer == null) {
            return null;
        }
        CustomerResponse customerResponse = new CustomerResponse();
        customerResponse.setTenantId(customer.getTenantId().id());
        customerResponse.setUserId(customer.getUserId().id());
        customerResponse.setCustomerId(customer.getId().id());
        customerResponse.setName(customer.getName());
        customerResponse.setMobile(customer.getMobile());
        customerResponse.setCertificateType(customer.getCertificateType().code());
        customerResponse.setCertificateNumber(customer.getCertificateNumber());
        return customerResponse;
    }

    public static List<CustomerResponse> toCustomerResponseList(List<Customer> customerList) {
        List<CustomerResponse> customerResponseList = new ArrayList<>(customerList.size());
        if (!customerList.isEmpty()) {
            customerList.forEach(customer -> {
                CustomerResponse customerResponse = toCustomerResponse(customer);
                customerResponseList.add(customerResponse);
            });
            return customerResponseList;
        }
        return Collections.emptyList();
    }
}
